<!DOCTYPE html>
<html>
<head>
    <title>计算属性完整写法</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <table>
            <tr>
                <td>姓：<input type="text" name="firstname" v-model="firstname"> + 名：<input type="text" name="lastname" v-model="lastname"> = {{ fullName }}</td> <br>
                <input type="button" value="改名卡" @click="changeName()">
            </tr>
        </table>
    </div>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                firstname: "刘",
                lastname: "备"
            },
            methods: {
                changeName() {
                    this.fullName = "陈奇123"
                }
            },
            computed: {
                fullName: {
                    get() {
                        return this.firstname + this.lastname
                    },
                    set(value) {
                        this.firstname = value.slice(0, 1)
                        this.lastname = value.slice(1)
                    }
                }
            }
        })
    </script>
</body>
</html>